package org.dtrd.modules.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.dtrd.modules.system.entity.bean.qiyeweixin.QwClientBaseInfo;
import org.dtrd.modules.system.entity.po.DtrdEntRdQwClient;
import org.dtrd.modules.system.mapper.DtrdEntRdQwClientMapper;
import org.dtrd.modules.system.service.IDtrdEntRdQwClientService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 萧
 * @date 2021-11-11 10:54:11
 **/
@Service
@DS("multi-datasource1")
@Slf4j
public class DtrdEntRdQwClientServiceImpl extends ServiceImpl<DtrdEntRdQwClientMapper, DtrdEntRdQwClient> implements IDtrdEntRdQwClientService {

    @Override
    public void saveExternalContact(QwClientBaseInfo info, Integer patientId, String mobile) {
        log.info("DtrdEntRdQwClientServiceImpl.saveExternalContact.[info, patientId, mobile]=" + mobile);
        DtrdEntRdQwClient po = getRecordById(info.getExternal_userid());
        if (po == null) {
            po = new DtrdEntRdQwClient().init();
        }
        po.parseFromQwClientBaseInfo(info);
        po.setUpdateTime(new Date());
        po.setMobile(mobile);
        po.setPatientId(patientId);
        log.info("DtrdEntRdQwClientServiceImpl.saveExternalContact.[info, patientId, mobile] "+po);
        saveOrUpdate(po);
    }

    @Override
    public DtrdEntRdQwClient getRecordById(String externalUserId) {
        return baseMapper.getRecordById(externalUserId);
    }

    @Override
    public List<QwClientBaseInfo> selectRecordByUserIds(String userIds) {
        return baseMapper.selectRecordByUserIds(userIds);
    }
}
